Generate a two-dimensional array with (i * j) valuesΒΆ
Write a python program which takes two digits M (rows) and N (columns) as input
and generates a two-dimensional array. The element value in the i-th row
and j-th column of the array should be i*j.
Note :
i = 0, 1, .., M-1
j = 0, 1, .., N-1
Test Data :
Rows = 3, Columns = 4
Expected Result :
[
[0, 0, 0, 0],
[0, 1, 2, 3],
[0, 2, 4, 6],
]
M = int(input("Input number of rows: "))
N = int(input("Input number of columns: "))
LOL = [[0 for j in range(N)] for i in range(M)]
# LOL = [[0 for j in range(3)] for i in range(4)]
# [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(M):
for j in range(N):
LOL[row][col] = i * j
print(LOL)
Output:
Input number of rows: 3
Input number of columns: 4
[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]